/*
2021-8-10
https://www.acwing.com/problem/content/1252/
*/
#include<cstring>
#include<iostream>
#include<algorithm>

using namespace std;
const int N=40010;
int n,m;
int f[N];

void init()
{
    for(int i=0;i<n*n;i++)
        f[i]=i;
}

int find(int x)
{
    if(x!=f[x]) f[x]=find(f[x]);
    return f[x];
}

int main()
{
    cin>>n>>m;
    init();
    int res=0;
    
    for(int i=1;i<=m;i++)
    {
        int x,y;
        char op;
        cin>>x>>y>>op;
        x--,y--;
        
        int a=x*n+y;
        int b;
        
        if(op=='D') b=(x+1)*n+y;
        else b=x*n+y+1;
        
        if(find(a)==find(b))
        {
            res=i;
            break;
        }
        else f[find(a)]=find(b);
        
    }
    
    if(res==0) puts("draw");
    else cout<<res<<endl;
    
    return 0;
}

